<template>
    <h1>注册页面</h1>

    <table>
        <tr>
            <td>账号</td>
            <td>
                <input type="text" v-model="info.L_Name"  />
            </td>
        </tr>

        <tr>
            <td>密码</td>
            <td>
                <input type="password" v-model="info.L_Pwd" />
            </td>
        </tr>

        <tr>
            <td colspan="2">
                <input type="button" value="注册" @click="AddUser" />
            </td>
        </tr>

    </table>

</template>

<script setup lang="ts">

import { ref } from 'vue';
import axios from 'axios';
import { useRouter } from 'vue-router';

const router = useRouter();


const info = ref({
    L_Name:'',
    L_Pwd:''
})

const AddUser = () => {
    //密码不能为空
    if(info.value.L_Pwd ==""){
        alert('密码不能为空');
        return;
    }

    axios({
        method:'post',
        url:'http://localhost:62821/api/Default/AddLoginData',
        data:{
            L_Name:info.value.L_Name,
            L_Pwd:info.value.L_Pwd
        }
    })
    .then(res => {
        console.log(res.data)
        if(res.data>0){
            alert('注册成功');
            router.push('/Login');
        }
        else if(res.data==-1){
            alert('用户名不能重复，请重新输入');
            return;
        }
        else{
            alert('注册失败');
            return;
        }
    })
    .catch(err => {
        console.log(err)
    })
}

</script>
